﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IFClientDLL.Calc;
using HCY.CTP.DBShangZheng;

namespace IFClientDLL.MyCalc.CalcOrder
{
    public class CalcOrder_LimitTime : CalcOrder_Empty
    {
        public int MinTime { get { return 2; } }
        public int MaxTime { get { return 100; } }
        public const int DefaultTime = 10;
        private int _limitTime;
        public CalcOrder_LimitTime(ITryIF tryif, int limitTime = DefaultTime)
            : base(tryif)
        {
            _limitTime = limitTime;
        }
        protected override void CalcOrder(IFServerDLL.Model.OrderBase order, MyIF myif)
        {
            DateTime dt = order.OrdTime;
            if (order.LastTradeTime != null)
            {
                dt = order.LastTradeTime.Value;
            }
            if ((myif.MarketTime - dt).TotalSeconds > _limitTime)
            {
                _tryif.Calc.CalcCmd.CancelOrder(this, myif, order);
                myif.AddCalcMsg(new CalcMsg(this, "Cancel the order onhand " + order.OrdID));
            }
            else
            {
                myif.AddCalcMsg(new CalcMsg(this, " do not need cancel."));
            }
        }
        public override string CalcName
        {
            get { return "Order Limit Time " + _limitTime; }
        }


    }
}
